package com.herionthenet;

import java.nio.ByteBuffer;

public abstract class FrameEncoder {
	
	protected byte[] header;
	protected byte[] tail;
	
	public FrameEncoder(){
		this(null, null);
	}
	
	public FrameEncoder(byte[] tail){
		this(null, tail);
	}
	
	public FrameEncoder(byte[] header, byte[] tail){		
		this.header = header;
		this.tail = tail;
	}
	
	public abstract ByteBuffer encode(Object message);	

	protected void setHeader(ByteBuffer buffer) {
		if(header == null || header.length == 0)
			return;
		
		for(byte b : header)
			buffer.put(b);
	}

	protected void setTail(ByteBuffer buffer) {
		if(tail == null || tail.length == 0)
			return;
		
		for(byte b : tail)
			buffer.put(b);
	}
	
}
